import org.authsum.stitches.Helper


class SearchControllerTests extends GroovyTestCase {
	def helper

    def stitchesService
	
	
	
	
	void testSearchKeyword() {
		Long contentDefId = helper.getContentDefId(name:"testSearchKeyword")
		
		
		
		
		//add String attribute
		Long attributeId= helper.getAttributeId(attributeName:'testSearchKeyword',contentDefId:contentDefId,valueType:"String")		
		
		//create content
		Long contentId = helper.getContentId(contentDefId:contentDefId,name:"testSearchKeyword")
		//create content version
		Long contentVersionId = helper.getContentVersionId(contentId:contentId)
		
		///Long contentVersionId,Long attributeId,String filePath,Integer myIntegerValue,String myStringValue
		Long attributeValueId = helper.getAttributeValueId(contentVersionId:contentVersionId,attributeId:attributeId,myStringValue:"testSearchKeyword")
		
		
		def controller = new SearchController()
    	controller.stitchesService  = stitchesService
		//need to send contentVersionId, attributeId and string value
		
		controller.request.parameters = ['keywords':"testSearchKeyword"]
		controller.search()
		
		
		
	}
	
	
	
	
	void testSearchByTag() {
		Long contentDefId = helper.getContentDefId(name:"testSearchByTag")
		
		
		
		
		//add String attribute
		Long attributeId= helper.getAttributeId(attributeName:'testSearchByTag',contentDefId:contentDefId,valueType:"String")	
		
		//create content
		Long contentId = helper.getContentId(contentDefId:contentDefId,name:"testSearchByTag")
		//create content version
		Long contentVersionId = helper.getContentVersionId(contentId:contentId)
		
		Long attributeValueId = helper.getAttributeValueId(contentVersionId:contentVersionId,attributeId:attributeId,myStringValue:"testSearchKeyword")
		
			
		
		
		Map parms = ['name':'testSearchByTag']
		Long tagId = helper.getTagId(parms)
		
		helper.addTagToContent(tagId,contentVersionId)
		
		def controller = new SearchController()
    	controller.stitchesService  = stitchesService
		//need to send contentVersionId, attributeId and string value
		
		controller.request.parameters = ['keywords':"testSearchKeyword",'tagId':tagId.toString()]
		controller.search()
		
		
		
	}
	

	//this will search and restrict by folder
	void testSearchByFolder() {
		Long contentDefId = helper.getContentDefId(name:"testSearchByFolder")
		
		
		
		
		//add String attribute
		Long attributeId= helper.getAttributeId(attributeName:'testSearchByFolder',contentDefId:contentDefId,valueType:"String")	
		
		//create content
		Long contentId = helper.getContentId(contentDefId:contentDefId,name:"testSearchByFolder")
		//create content version
		Long contentVersionId = helper.getContentVersionId(contentId:contentId)
		
		Long attributeValueId = helper.getAttributeValueId(contentVersionId:contentVersionId,attributeId:attributeId,myStringValue:"testSearchByFolder")
		
				
		Map parms = ['name':'testSearchByFolder']
		Long folderId = helper.getFolderId(parms)
		
		helper.addFolderToContent(folderId,contentId)
		
		def controller = new SearchController()
		//need to send contentVersionId, attributeId and string value
		    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['keywords':"testSearchKeyword",'folderId':folderId.toString()]
		controller.search()
		
		
		
	}
	
	
}
